using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;

public class MiningTower : TowerHolder
{
    public float resourceCollectTime;
    public float counterDownTime;
    public float liveTime;

    public override void Update()
    {
        LiveTime();
        AddResource();
        if(health <= 0){
            Destroy(gameObject);
        }
        base.Update();
    }

    public void AddResource(){
        counterDownTime -= Time.deltaTime;
        if(counterDownTime <= 0){
            counterDownTime = resourceCollectTime;
            BoxCollider2D boxCollider2D = gameObject.GetComponent<BoxCollider2D>();
            Collider2D[] colliders = Physics2D.OverlapBoxAll(transform.position + (Vector3)boxCollider2D.offset , boxCollider2D.size , 0);
            foreach (var item in colliders){
                if(item.CompareTag("Glass")){
                    ResourceUI.instance.glassCount++;
                }else if(item.CompareTag("Ore")){
                    ResourceUI.instance.oreCount++;
                }
            }
        }
    }
    public void LiveTime(){
        liveTime -= Time.deltaTime;
        if(liveTime <= 0){
            Destroy(gameObject);
        }       
    }
}
